<?php
namespace app\index\model;
use think\Model;
use think\Db;
use think\Cache;

class KnowUserRecord extends Model
{
	public function getUserCount($param, $column = 'sum', $field = '')
	{
		$user = $param['user'] ?: user();

		return self::where('user_id', $user['id'])
						->when($param['course_ids'], function($query) use ($param){
							$query->where('course.course_id', 'in', $param['course_ids']);
						})
						->when($param['type_id'], function($query) use ($param){
							$query->where('course.type_id', $param['type_id']);
						})
						->when($param['s_id'], function($query) use ($param){
							$query->where('course.s_id', $param['s_id']);
						})
						->when($param['status'], function($query) use ($param){
							$query->where('status', $param['status']);
						})
						->when($param['start'], function($query) use ($param){
							$query->where('know_user_record.updated_time', 'between', [$param['start'], $param['end']]);
						})
						->where('course.is_show', 1)
						->where('type.is_show', 1)
						->where('nav.is_show', 1)
						->where('s_show', 1)
						->join('course', 'course.course_id=know_user_record.course_id')
						->join('specific', 'course.s_id=specific.s_id')
						->join('type', 'course.type_id=type.type_id')
						->join('nav', 'course.nav_id=nav.nav_id')
						->{$column}($field);
	}


	public function getDetail($param)
	{
		$user = user();

		return self::where('user_id', $user['id'])
						->where('course_id', $param['id'])
						->find();
	}
}